from pygame import draw
import pygame


# 绘制方块
def draw_rock(sc, fillcolor = (0, 0, 0), outlinecolor = (255, 255, 255), x = 0, y = 0, size = 10):
    draw.rect(sc, fillcolor, pygame.Rect(x, y, size, size))
    draw.line(sc, outlinecolor, (x, y), (x + size, y))
    draw.line(sc, outlinecolor, (x, y), (x, y + size))
    draw.line(sc, outlinecolor, (x + size, y), (x + size, y + size))
    draw.line(sc, outlinecolor, (x, y + size), (x + size, y + size))


# 绘制三面墙壁，底下固定为十二个方块
def draw_wall(screen, color, wallRock_sz, height):
    if height // wallRock_sz != height / wallRock_sz:
        raise "wallRock's size does not match the wall's height! note:height/wallRock_sz must be integer."
    obstacle_yx = dict()
    for i in range(height // wallRock_sz - 1):
        y = i * wallRock_sz
        draw_rock(sc = screen, x = 0, y = y, size = wallRock_sz, fillcolor = color)
        draw_rock(sc = screen, x = wallRock_sz * 11, y = y, size = wallRock_sz, fillcolor = color)
        obstacle_yx[y] = [0, wallRock_sz * 11]
    y = height - wallRock_sz
    obstacle_yx[y] = []
    for i in range(12):
        x = i * wallRock_sz
        draw_rock(sc = screen, x = x, y = y, size = wallRock_sz, fillcolor = color)
        obstacle_yx[y].append(x)
    return obstacle_yx


# 根据给定的rock_kind绘制具体样式的俄罗斯方块
def draw_russian_rock(screen, x, y, rock_kind, rock_sz, color1 = (0, 0, 0), color2 = (255, 255, 255)):
    lr, lc = len(rock_kind), len(rock_kind[0])
    for i in range(lr):
        for j in range(lc):
            if rock_kind[i][j]:
                draw_rock(sc = screen, x = x + j * rock_sz, y = y + i * rock_sz, size = rock_sz, fillcolor = color1,
                          outlinecolor = color2)
